2 Problem: 10986 - Sending email (UVa Online Judge)
3 Andrés Mejía-Posada (http://github.com/andmej/acm)
18 edge(int t
, int w
) : to(t
), weight(w
) {}
19 bool operator < (const edge
&that
) const {
20 return weight
> that
.weight
;
29 scanf("%d %d %d %d", &n
, &m
, &s
, &t
);
33 scanf("%d %d %d", &u
, &v
, &w
);
34 g
[u
].push_back(edge(v
, w
));
35 g
[v
].push_back(edge(u
, w
));
39 for (int i
=0; i
<n
; ++i
) d
[i
] = INT_MAX
;
41 priority_queue
<edge
> q
;
43 while (q
.empty() == false){
44 int node
= q
.top().to
;
45 int dist
= q
.top().weight
;
48 if (dist
> d
[node
]) continue;
51 for (int i
=0; i
<g
[node
].size(); ++i
){
52 int to
= g
[node
][i
].to
;
53 int w_extra
= g
[node
][i
].weight
;
55 if (dist
+ w_extra
< d
[to
]){
56 d
[to
] = dist
+ w_extra
;
57 q
.push(edge(to
, d
[to
]));
61 printf("Case #%d: ", C
);
62 if (d
[t
] < INT_MAX
) printf("%d\n", d
[t
]);
63 else printf("unreachable\n");